 <?php

  try {
  $form = $_POST['form'];
  $EmployeeaddressUid = $form['EMPLOYEEADDRESS_UID'];
  $EmployeeId = $form['EMPLOYEE_ID'];
  $EmployeestateId = $form['EMPLOYEESTATE_ID'];
  $Employeeaddress1 = $form['EMPLOYEEADDRESS1'];
  $Employeeaddress2 = $form['EMPLOYEEADDRESS2'];
  $Employeecity = $form['EMPLOYEECITY'];
  $Employeecounty = $form['EMPLOYEECOUNTY'];
  $Employeezipcode = $form['EMPLOYEEZIPCODE'];
  $Employeeactive = $form['EMPLOYEEACTIVE'];

  require_once ( PATH_PLUGINS . 'hr' . PATH_SEP . 'class.hr.php');
  $pluginObj = new hrClass ();

  require_once ( "classes/model/HrEmployeeAddress.php" );

     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = HrEmployeeAddressPeer::retrieveByPK( $EmployeeaddressUid );
     if ( ! ( is_object ( $tr ) &&  get_class ($tr) == 'HrEmployeeAddress' ) ) {
       $tr = new HrEmployeeAddress();
     }
     $tr->setEmployeeaddressUid( $EmployeeaddressUid );
     $tr->setEmployeeId( $EmployeeId );
     $tr->setEmployeestateId( $EmployeestateId );
     $tr->setEmployeeaddress1( $Employeeaddress1 );
     $tr->setEmployeeaddress2( $Employeeaddress2 );
     $tr->setEmployeecity( $Employeecity );
     $tr->setEmployeecounty( $Employeecounty );
     $tr->setEmployeezipcode( $Employeezipcode );
     $tr->setEmployeeactive( $Employeeactive );

     if ($tr->validate() ) {
       // we save it, since we get no validation errors, or do whatever else you like.
       $res = $tr->save();
     }
     else {
       // Something went wrong. We can now get the validationFailures and handle them.
       $msg = '';
       $validationFailuresArray = $tr->getValidationFailures();
       foreach($validationFailuresArray as $objValidationFailure) {
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       }
       //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
     }
    //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');

    //to do: uniform  coderror structures for all classes
  
  //if ( $res['codError'] < 0 ) {
  //  G::SendMessageText ( $res['message'] , 'error' );  
  //}
  G::Header('location: hrEmployeeAddressList');

  }
  catch ( Exception $e ) {
    $G_PUBLISH = new Publisher;
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
  }
